package com.example.ivos.geofence.controller;

import com.example.ivos.base.response.JsonResult;
import com.example.ivos.geofence.pojo.dto.GeofenceParam;
import com.example.ivos.geofence.pojo.dto.GeofenceQuery;
import com.example.ivos.geofence.pojo.vo.GeofenceVO;
import com.example.ivos.geofence.service.GeofenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "电子围栏管理模块")
@RestController
@Slf4j
@RequestMapping("/v1/geofence/")
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;

    @ApiOperation("围栏列表")
    @GetMapping("select")
    public JsonResult select(GeofenceQuery geofenceQuery) {
        log.debug("查询围栏列表geofenceQuery:{}", geofenceQuery);
        List<GeofenceVO> geofenceVOList=geofenceService.select(geofenceQuery);
        return JsonResult.ok(geofenceVOList);
    }

    @ApiOperation("管理围栏信息")
    @PostMapping("save")
    public JsonResult save(GeofenceParam geofenceParam){
        log.debug("管理围栏geofenceParam:{}", geofenceParam);
        geofenceService.save(geofenceParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除围栏")
    @PostMapping("delGeofence/{id}")
    public JsonResult delGeofence(@PathVariable Long id){
        log.debug("删除围栏id:{}", id);
        geofenceService.del(id);
        return JsonResult.ok();
    }

}
